package com.atguigu.order.controller;

import com.atguigu.order.domain.Order;
import com.atguigu.order.properties.OrderProperties;
import com.atguigu.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@RequestMapping("/api/order")
@RefreshScope // 刷新配置NOCOS
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderProperties orderProperties;

    @Value("${order1.timeout}")
    private String timeout;

    @GetMapping("/config")
    public String getConfig(){
        return "order1.timeout:"+timeout + "order.autoConfime:" + orderProperties.getAutoConfime() + "order.autoCancel:" + orderProperties.getAutoCancel();
    }

    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId,
                             @RequestParam("productId") Long productId ){
        return orderService.generate(userId, productId);
    }
}
